package cn.springmvc.controller;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import cn.springmvc.model.User;
import cn.springmvc.service.UserService;

@Controller
@RequestMapping("/mvc")
public class MainController {
	public static final Logger logger = Logger.getLogger(MainController.class);

	@Autowired
	UserService userService;
	
	
	@RequestMapping("/index")
	public String index() {
		System.out.println(111);
		return "index";
	}

	@RequestMapping("/querylist")
	public String querylist(ModelAndView modelAndView) {
		String name = "world";
		List<User> list = userService.queryUserList();
		for (int i = 0; i < list.size(); i++) {
			User user = list.get(i);
			logger.debug("user = "+user.getNickname());
		}
		modelAndView.addObject("view", list);
		return "index";
	}

}
